<?php

//echo br(3); ###########################################################################################

	$TEMP->set_file(array('handle' => DIR_VIEW_STUDENTS . 'myPayments.html'));
	
	$SAID = (!empty($_GET['said'])) ? _GET('said') : $activeSemester['sem_linker_idFK'];
	
	$semFeesLinkerListing 	= $DSC->getSemFeesLinkerListingActive($SAID);
	
	$semesterLabel 			= $DSC->getSemesterLabel($SAID);
	$semFeesLinkerListing 	= $DSC->getSemFeesLinkerListingActive($SAID);
	$totalUnits 			= $DSC->getTotalUnitsPerSemesterLinkerActive($SAID, $logUserID);
	$semDesc 				= $DSC->getSemesterDescViaLinker($SAID);

	$feesListing = '';
	if (!empty($semFeesLinkerListing)) {
		$descFee = '';
		$descVal = '';
		$amountTotalValue = 0;
		foreach($semFeesLinkerListing as $semFeesLinkerListingValue) {
			if ( $semFeesLinkerListingValue['fee_idFK'] == 1 ) {
				$descFee = "Tuition Fee (" . $totalUnits . " units * P " . number_format($semFeesLinkerListingValue['amount']) . ")";
				$descVal = (int)$totalUnits * (int)$semFeesLinkerListingValue['amount'];
			}
			else {
				$descFee = $semFeesLinkerListingValue['fee_desc'];
				$descVal = $semFeesLinkerListingValue['amount'];
			}
			
			$feesListing .= '<div class="reg-fee-enroll">
								<div class="reg-fee-enroll-label">&nbsp;&nbsp;&nbsp;' . $descFee . '</div>
								<div class="reg-fee-enroll-dot">:</div>
								<div class="reg-fee-enroll-value">Php ' . number_format($descVal) . '</div>
							</div>';
			$amountTotalValue += $descVal;
		}
		$feesListing .= '<div class="reg-fee-enroll">
							<div class="reg-fee-enroll-label">&nbsp;&nbsp;&nbsp;<strong>TOTAL</strong></div>
							<div class="reg-fee-enroll-dot"><strong>:</strong></div>
							<div class="reg-fee-enroll-total"><strong>Php ' . number_format($amountTotalValue) . '</strong></div>
						</div>';
	}
	
	$studentPaymentHistory = $DSC->getStudentPaymentHistory($SAID, $logUserID, $strCourseID);
	
	if ( !empty($studentPaymentHistory) ) {
		$TEMP->set_block('handle',  'payments', 'paymentsRow');
		$bgcolor 	 = LOOPING_FFF;
		$numCount 	 = 1;
		$amountFull	 = 0;
		$totalAmount = 0;
		foreach($studentPaymentHistory as $studentPaymentHistoryValue) {
			
			if ( $studentPaymentHistoryValue['payment_mode'] == 'F' ) {
				$payment_mode = "Full Payment";
				$amountFull++;
			}
			else {
				$payment_mode = "Partial Payment";
			}
			
			$TEMP->set_var(array('date' 		=> shortMdYwithTimeDay($studentPaymentHistoryValue['timestamp']),
								 'amount'		=> 'Php ' . number_format($studentPaymentHistoryValue['amount'],2),
								 'remarks'		=> $payment_mode,
								 'numbering'	=> $numCount,
								 'bgcolor'		=> $bgcolor
								));
								
			$TEMP->parse('paymentsRow', 'payments', true);
			$bgcolor = ($bgcolor == LOOPING_F0F) ? LOOPING_FFF : LOOPING_F0F;
			$numCount++;
			$totalAmount += $studentPaymentHistoryValue['amount'];
		}
	
		$fullyPaid = ( $totalAmount >= $amountTotalValue || $amountFull > 0 ) ? 'Fully paid' : '';
	}
	else {
		$TEMP->set_var(array('date' 		=> '',
							 'amount'		=> '',
							 'remarks'		=> '',
							 'numbering'	=> '',
							 'bgcolor'		=> ''
							));
		$totalAmount = 0;
		$fullyPaid 	 = '';
	}
	
	$TEMP->set_var(array('stud_sub_menu'	=> $studentDesignName,
						 'stud_active_sem'	=> $studActiveSemester,
						 'total_fees'		=> $feesListing,
						 'fully_paid'		=> $fullyPaid,
						 'total_amount'		=> 'Php ' . number_format($totalAmount,2),
						 'sem_desc'			=> $semDesc['sem_desc'],
						 'sem_code'			=> $semDesc['sem_code'],
						));
?>